/*
 * 上海远境文化传媒有限公司 版权所有
 */
package ext.dbutils;

import org.apache.commons.dbutils.QueryRunner;
import org.sql2o.Sql2o;
import play.Logger;
import play.db.DB;
import play.db.DBPlugin;

import javax.sql.DataSource;

/**
 * DBUtils操作封装.
 */
public class DBUtils {

    private static Sql2o sql2o = null;

    private static QueryRunner queryRunner = null;

    public static QueryRunner queryRunner() {
        if (queryRunner == null) {
            DataSource dataSource = DB.getDataSource();
            queryRunner = new QueryRunner(dataSource);
        }
        return queryRunner;
    }

    public static Sql2o sql2o() {
        if (sql2o == null) {
            DataSource dataSource = DB.getDataSource();
            sql2o = new Sql2o(dataSource);
        }
        return sql2o;
    }

    public static boolean isMySQL() {
        Logger.debug("LOG01080: DBPlugin.url = %s", DBPlugin.url);
        return DBPlugin.url.contains("mysql");
    }

    public static boolean isOracle() {
        Logger.debug("LOG01082: DBPlugin.url = %s", DBPlugin.url);
        return DBPlugin.url.contains("oracle");
    }


    public static boolean isSQLServer() {
        Logger.debug("LOG01083: DBPlugin.url = %s", DBPlugin.url);
        return DBPlugin.url.contains("sqlserver");
    }
}
